$(function(){
	order.orderFun();
	order.delorderFun();
});
var order = {
	orderFun:function(){
		var orderUrl = '/search/orderinfo';
		publicDom.post(orderUrl,'',function(responseData){
			if (responseData.Code === 0) {
				var data = responseData.Data;
				$("#orderList").html('');
				for (var i = 0; i < data.length; i++) {
					if (data[i].Cancel === false) {
						var status = '';
						if (data[i].OrderStatus === 0) {
							OrderStatus = '已购买';
							status = '删除订单';
						}
						else {
							OrderStatus = '待付款';
							status = '去付款';
						}
						var seat = data[i].SeatId;
						var row = parseInt(seat/10);
						var col = seat%10;
						if (row !== 0 && col !== 0) {
							var SeatNum = (row+1)+'排'+col+'列';
						}
						else if (row !== 0 && col === 0) {
							var SeatNum = row+'排'+'10列';
						}
						else if (row === 0) {
							var SeatNum = '1排'+col+'列';
						}
						
						var myRefundtime = new Date(data[i].Refundtime);
						var Refundtime =  myRefundtime.getFullYear()+'年'+(myRefundtime.getMonth()+1)+'月'+myRefundtime.getDate()+'日';
						$("#orderList").append('<tr class="odd">'
	                                    +'<td class="  sorting_1">'+data[i].Number+'</td>'
	                                    +'<td class=" ">'+data[i].TickerNum+'</td>'
	                                    +'<td class=" ">'+Refundtime+'</td>'
	                                    +'<td class=" ">'+SeatNum+'</td>'
	                                    +'<td>'+OrderStatus+'</td>'
	                                    +'<td><button class="btn btn-warning btn-sm turn_to_buy">'+status+'</button><button class="btn btn-warning btn-sm turn_to_buy del" orderid='+data[i].Id+'>删除订单</button></td>'
	                                +'</tr>');
					}
				}
			}
			else {
				layer.msg(responseData.Msg);
			}
		},function(err){
			layer.msg(responseData.Msg);
		})
	},
	delorderFun:function(){
		$(".del").click(function(){
			var delUrl = '/refund';
			orderid = $(this).attr('orderid');
			var orderid = {
				orderid: orderid
			};
			publicDom.post(delUrl,orderid,function(responseData){
				if (responseData.Code === 0) {
					layer.msg(responseData.Msg);
					order.orderFun();
					order.delorderFun();
				}
				else {
					layer.msg(responseData.Msg);
				}
			},function(responseData){
				layer.msg(responseData.Msg);
			})
		})
	}
}